<?php
use app\models\Mall;
use yii\helpers\Url;

$web = Url::base();
$integral_unit = Mall::getCurrentInstitutionIntegralUnit();
$institution_code = Mall::getCurrentInstitutionCode();
$site_name = Mall::getCurrentInstitutionSiteName();
$this->title = $goodsListTitle ? $goodsListTitle : $site_name . '-商品列表'
?>



<link rel="stylesheet" type="text/css" href="<?= $web ?>/css/mall/goods-list.css"/>
<script>
    function lazy_goods_img(){
        //图片延时加载
        $(".show img").lazyload({
            effect: "fadeIn",
            skip_invisible:false,
            placeholder:"<?= $web ?>/images/mall-m/goods-list-loading.jpg"
        });

    }
    hrefGoodsListByIntegral =function(){
        var integralFrom=parseInt($('.minimum').val());
        var integralTo=parseInt($('.highest').val());
        if(isNaN(integralFrom)){
            integralFrom=0;
        }
        if(isNaN(integralTo)){
            integralTo=0;
        }
        var link_url="<?=Url::to(['mall/goods-list','institution_code'=>$institution_code,'sort'=>2])?>";
        window.location.href=link_url+"&integralFrom="+integralFrom+"&integralTo="+integralTo;
    };
    var currentSort =<?=$sort?>;
    var currentCv =<?=$cv?>;
    function setSortType(sort) {
        var href = window.location.href;
        href = setUrlParam(href, 'sort', sort);
        href = setUrlParam(href, 'page', 1);
        window.location.href = href;
    }
    function click_default_order() {
        if (currentSort != 0) {
            setSortType(0);
        }
    }
    function click_new_order() {
        if (currentSort != 3) {
            setSortType(3);
        }
    }
    function click_price_order() {
        var sort = 1;
        if (currentSort == 1) {
            sort = 2;
        }
        setSortType(sort);
    }
    function href_page(page) {
        var currentPage=<?=$page?>;
        page=parseInt(page);
        if(isNaN(page)){
            page=0;
        }
        if(page<1){
            page=1;
        }
        var maxPage=<?=$maxPage?>;
        if(page>maxPage){
            page=maxPage;
        }
        if(page==currentPage){
            return;
        }
        var href = window.location.href;
        href = setUrlParam(href, 'page', page);
        window.location.href = href;
    }
    $(function($){
        lazy_goods_img();
    });
</script>
<div class="list-nav">
    <div class="list-gps">
        <ul>
            <li class="fl lbcur list-gps-name">
                <a >积分区间</a>
            </li>
            <li class="fl <?=$integralFrom=='0' && $integralTo=='50' ? 'lbcur' :''?>">
                <a href="<?=Url::to(['mall/goods-list','integralFrom'=>0,'integralTo'=>50,'sort'=>2,'institution_code' => $institution_code])?>">0-50</a>
            </li>
            <li class="fl <?=$integralFrom=='50' && $integralTo=='100' ? 'lbcur' :''?>">
                <a href="<?=Url::to(['mall/goods-list','integralFrom'=>50,'integralTo'=>100,'sort'=>2,'institution_code' => $institution_code])?>">50-100</a>
            </li>
            <li class="fl <?=$integralFrom=='100' && $integralTo=='200' ? 'lbcur' :''?>">
                <a href="<?=Url::to(['mall/goods-list','integralFrom'=>100,'integralTo'=>200,'sort'=>2,'institution_code' => $institution_code])?>">100-200</a>
            </li>
            <li class="fl <?=$integralFrom=='200' && $integralTo=='300' ? 'lbcur' :''?>">
                <a href="<?=Url::to(['mall/goods-list','integralFrom'=>200,'integralTo'=>300,'sort'=>2,'institution_code' => $institution_code])?>">200-300</a>
            </li>
            <li class="fl <?=$integralFrom=='300' && $integralTo=='400' ? 'lbcur' :''?>">
                <a href="<?=Url::to(['mall/goods-list','integralFrom'=>300,'integralTo'=>400,'sort'=>2,'institution_code' => $institution_code])?>">300-400</a>
            </li>
            <li class="fl <?=$integralFrom=='400' && $integralTo=='500' ? 'lbcur' :''?>">
                <a href="<?=Url::to(['mall/goods-list','integralFrom'=>400,'integralTo'=>500,'sort'=>2,'institution_code' => $institution_code])?>">400-500</a>
            </li>
            <li class="fl <?=$integralFrom=='500' && $integralTo=='600' ? 'lbcur' :''?>">
                <a href="<?=Url::to(['mall/goods-list','integralFrom'=>500,'integralTo'=>600,'sort'=>2,'institution_code' => $institution_code])?>">500-600</a>
            </li>
            <li class="fl <?=$integralFrom=='600' && $integralTo=='700' ? 'lbcur' :''?>">
                <a href="<?=Url::to(['mall/goods-list','integralFrom'=>600,'integralTo'=>700,'sort'=>2,'institution_code' => $institution_code])?>">600-700</a>
            </li>
            <li class="fl fistmr <?=$integralFrom=='700' && $integralTo=='800' ? 'lbcur' :''?>">
                <a href="<?=Url::to(['mall/goods-list','integralFrom'=>700,'integralTo'=>800,'sort'=>2,'institution_code' => $institution_code])?>">700-800</a>
            </li>
            <li class="fl <?=$integralFrom=='800' && $integralTo=='900' ? 'lbcur' :''?>">
                <a href="<?=Url::to(['mall/goods-list','integralFrom'=>800,'integralTo'=>900,'sort'=>2,'institution_code' => $institution_code])?>">800-900</a>
            </li>
            <li class="fl <?=$integralFrom=='1000' && $integralTo==null ? 'lbcur' :''?>">
                <a href="<?=Url::to(['mall/goods-list','integralFrom'=>1000,'sort'=>2,'institution_code' => $institution_code])?>">1000以上</a>
            </li>

            <li class="import-section">
                <div class="orderplss fl">
                    <input type="text" class="minimum" value="<?=$integralFrom ? $integralFrom : ''?>" placeholder="最低积分" />
                    <span>-</span>
                    <input type="text" class="highest" value="<?=$integralTo ? $integralTo : ''?>" placeholder="最高积分" />
                    <a  class="orderplss-btn" href="javascript:hrefGoodsListByIntegral()">确定</a>
                </div>
            </li>
        </ul>

    </div>
</div>



<div class="order">
    <div class="orderpl">
        <div class="mrpx fl">
            <ul>
                <li class="default <?=$sort=='0' ? 'ordercur' : ''?>">
                    <a href="javascript:click_default_order()">默认</a>
                </li>
                <li class="<?=$sort=='3' ? 'ordercur' : ''?>">
                    <a href="javascript:click_new_order()">最新</a>
                </li>
                <li class="cost <?=$sort=='1' || $sort=='2' ? 'ordercur' : ''?>">
                    <a href="javascript:click_price_order()">价格</a>
                    <?php
                        if($sort!='1' && $sort!='2'){
                    ?>
                            <img class="arrow_up" src="<?=$web?>/images/mall/arrow_up.png" />
                            <img class="arrow_down" src="<?=$web?>/images/mall/arrow_down.png" />
                    <?php
                        }
                    ?>
                    <?php
                    if($sort=='1'){
                        ?>
                        <img class="arrow_up" src="<?=$web?>/images/mall/arrow_up_red.png" />
                        <img class="arrow_down" src="<?=$web?>/images/mall/arrow_down.png" />
                        <?php
                    }
                    ?>
                    <?php
                    if($sort=='2'){
                        ?>
                        <img class="arrow_up" src="<?=$web?>/images/mall/arrow_up.png" />
                        <img class="arrow_down" src="<?=$web?>/images/mall/arrow_down_red.png" />
                        <?php
                    }
                    ?>

                </li>
            </ul>

        </div>
    </div>
</div>


<div class="show">
    <ul>
        <?php
            foreach($items as $item){
        ?>
                <li>
                    <a href="<?=Url::to(['mall/goods-detail','goods_code'=> $item['code'],  'institution_code' => $institution_code]) ?>">
                        <img data-original="<?= $item['goods_image'] ? $item['goods_image'].'@300w': $web.'/images/mall-m/goods-list-nothing.jpg'?>" />
                        <p>
                            <?php
                            if($item['is_crossborder']=='1'){
                                ?>
                                <span class="cross-title-icon">跨境</span>
                                <?php
                            }
                            ?>
                            <?=$item['name']?>
                        </p>
                        <p class="integral-num">
                            <?php
                            if($item['is_activity']=='1'){
                            ?>
                                <span class="old"><?= intval($item['old_price']) ?> <?= $integral_unit ?></span>
                            <?php
                            }
                            ?>

                            <span class="now"><span><?= intval($item['selling_integral']) ?></span>&nbsp;&nbsp;<?= $integral_unit ?></span>
                        </p>
                    </a>
                </li>

        <?php
            }
        ?>
       <!-- <li >
					<a href="">
						<img src="imgs/goods.jpg" />
						<p>大牌时尚羊皮双肩包大牌时尚羊皮双肩包大牌时尚羊皮双肩包大牌时尚羊皮双肩包</p>
						<p class="integral-num">
							<span class="old">599 积分</span>
							 <span class="now"><span>199</span>&nbsp;&nbsp;积分</span>
						</p>
					</a>
				</li>-->




    </ul>
</div>
<div class="clfl"></div>
<div class="paging">
    <div class="pag-content">
        <div class="sum-page">
            <p class="total">共<?=$maxPage?>页</p>
            <p class="send">到第<input class="num" type="text" value=""/>页</p>
            <a href="javascript:href_page($('.num').val())" class="confirm-btn">确定</a>
        </div>
        <div class="page-list">
            <?php
                if($page>1){
            ?>
                    <a href="javascript:href_page(<?=$page-1?>)" class="previous-page">< 上一页</a>
            <?php
                }
            ?>
            <div class="page-num">
                <?php
                    $pagesList=\app\librarys\Tools::getJDPageNumList($page,$maxPage,6);
                    foreach($pagesList as $item){
                        if($item=='preDot' || $item=='lastDot'){
                            echo '<span class="page-num-list">...</span>';
                        }else {
                ?>
                            <a href="javascript:href_page(<?=$item?>)" class="page-num-list <?=(string)$page==$item ? '' :'page-border'?>"><?=$item?></a>
                <?php
                        }
                    }
                ?>

                   <!--
                   <a href="" class=" page-num-list">1</a>
                   <a href="" class="page-border page-num-list">2</a>
                    <a  href="" class="page-border page-num-list">3</a>
                    <span class="page-num-list">...</span>
                    <a href="" class="page-border page-num-list">20</a>-->
            </div>
            <?php
            if($page<$maxPage){
                ?>
                <a href="javascript:href_page(<?=$page+1?>)" class="next-page">下一页 ></a>
                <?php
            }
            ?>
        </div>
    </div>
</div>
